package com.wf.day_0531.test5;

import com.wf.day_0531.test2.Person;

import java.util.LinkedList;

/**
 * @author mpk
 * @since 2024/5/31 17:47:52
 */
//LinkedList作业：
//练习1：用LinkedList集合，模拟队列操作(存入的元素是Person对象)  1 2 3 ==>   12 3

//练习2：用LinkedList集合，模拟堆栈操作(存入的元素是Person对象)  1 23 ==>   3 2 1

public class Demo {
    public static void main(String[] args) {

        LinkedList<Person> people = new LinkedList<>();

        Person person = new Person("张三", 18);
        Person person1 = new Person("李四", 20);
        Person person2 = new Person("王五", 74);

        System.out.println("----队列----");
        people.addLast(person); // 进队列
        people.addLast(person1); // 进队列
        people.addLast(person2); // 进队列
        System.out.println("list.pop() = " + people.removeFirst());// 出队列
        System.out.println("list.pop() = " + people.removeFirst());// 出队列
        System.out.println("list.pop() = " + people.removeFirst());// 出队列


        System.out.println("----堆栈----");
        people.push(person); // 进栈
        people.push(person1); // 进栈
        people.push(person2); // 进栈


        System.out.println("list.pop() = " + people.pop());// 出栈
        System.out.println("list.pop() = " + people.pop());// 出栈
        System.out.println("list.pop() = " + people.pop());// 出栈

    }

}
